<?php
/**
 * Created by PhpStorm.
 * User: yangyulu
 * Date: 2020/4/15
 * Time: 下午4:20
 */

class Admin_orderController extends Admin_baseController{
    public function listAction(){
        $page = Request::getParams('page', 1);
        $pageSize = Request::getParams('pageSize', 20);

        $order_sn = Request::getParams('order_sn');

        $where = $value = $url = array();
        if ($order_sn) {
            $where[] = 'order_sn like ?';
            $value[] = '%' . $order_sn . '%';
            $url['order_sn'] = $order_sn;
        }
        $where[]="is_delete=?";
        $value[]=0;
        $total = self::model('orders')->count(null, $where, $value);
        $list = self::model('orders')->limit(($page - 1) * $pageSize, $pageSize)->order('orderId desc')->getAll($where, $value);
        foreach ($list as $k=>$v){
            $info=self::model("goods_orders")->getOne("order_id=?",$v["orderId"]);
            $list[$k]["goods_name"]=$info["goods_name"];
        }
        $this->assign(array(
            'page' => $page,
            'pageSize' => $pageSize,
            'total' => $total,
            'list' => $list,
            'order_sn' => $order_sn,
            'pageHtml' => self::instance('Pagination')->page($page)->num($pageSize)->total($total)->url(Router::getBaseUrl() . '/admin_order/list?' . ($url ? http_build_query($url) : '') . '&page=')->rendHtml(),
        ));
        $this->display();
    }

    public function fahuoAction(){
        $orderId=Request::getParams("orderId");
        $info= self::model('orders')->getOne(["orderId=?","status=?"],[$orderId,0]);
        if(empty($info)){
            Response::showMsg('信息不存在，无法发货');
        }
        $res=self::model('orders')->update(["status"=>1],"orderId=?",$orderId);
        if($res){
            Response::ajax(200, "发货成功");
        }else{
            Response::showMsg('发货失败');
        }
    }

}